package listbyorder.access201_300.test234;

import listbyorder.utils.ListNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/26 19:50
 */
public class Solution2 {

    // 方法二
    public boolean isPalindrome(ListNode head) {
        if (head == null || head.next == null) return true;
        List<Integer> list = new ArrayList<>();
        ListNode temp = head;
        while (temp != null) {
            list.add(temp.val);
            temp = temp.next;
        }
        int end = list.size() - 1;
        int start = 0;
        while (start < end) {
            if (!list.get(start++).equals(list.get(end--))) {
                return false;
            }
        }
        return true;
    }
}
